package com.sharemarking.wa.platform.service;

import com.sharemarking.wa.platform.utils.HttpSender;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author dxy
 */
@Service
public class MXTService {
    @Value("${mxt.username}")
    private String userName;
    @Value("${mxt.password}")
    private String password;


    public Boolean sendSMS(String mobile, String validateCode,String type) {

        String typeName = null;
        if (type.equals("LOGIN")){
            typeName = "登录";
        }else if (type.equals("REGISTER")){
            typeName = "注册";
        }else if (type.equals("PAY_PWD")){
            typeName = "设置支付密码";
        }else if (type.equals("FORGET_PSW")){
            typeName = "忘记密码";
        }

        String url = "http://www.weiwebs.cn/msg/HttpSendSM";// 应用地址
        String un = userName;// 账号
        String pw = password;// 密码
        String phone = mobile;// 手机号码，多个号码使用","分割
        String msg = "【环保大湾区】您好，您正在进行"+typeName+"操作，验证码是" + validateCode + ",请勿告诉他人";// 短信内容
        String rd = "true";// 是否需要状态报告，需要true，不需要false
        String ex = null;// 扩展码


        try {
            String returnString = HttpSender.batchSend(url, un, pw, phone, msg, rd, ex);
            if (returnString != null) {
                if (returnString.substring(returnString.indexOf(",") + 1, returnString.indexOf(",") + 2).equals("0")) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }


}



